package com.moive.news.tqnewsapplication.base.Adapter;

import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/22.
 */
public abstract class BaseRecyleViewAdapter<D,V extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<V> {

   protected List<D> arrayLists=new ArrayList<>();
    @Override
    public int getItemCount() {
        return arrayLists.size();
    }
    protected D getItem(int position){
       return arrayLists.get(position);
    }

    public void addItems(List<D> arrayList){
        arrayList.removeAll(arrayLists);
        this.arrayLists.addAll(arrayList);
        notifyDataSetChanged();
    }
    public void clearItems(){
        arrayLists.clear();
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(V holder, int position) {
        bindDataToView(holder,arrayLists.get(position),position);
    }

    protected abstract void bindDataToView(V ViewHolder,D item, int position);

}
